package com.g001.model.abilities;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.util.CachedResourceLoader;

public class Health extends Power {
	
	private final static int WIDTH = 28;
	private final static int HEIGTH = 45;
	
	private Image[] levelEnergy = new Image[6];
	private String str;

	public Health(final int value, final int max, final Vector2f position) throws SlickException{
		super(value, max, position);
		image = CachedResourceLoader.getInstance().getImage("data/g001/blocks.png").getSubImage(0, 287, 84, 89);
		levelEnergy [0] = image.getSubImage(0, 0, WIDTH, HEIGTH);
		levelEnergy[1] = image.getSubImage(WIDTH, 0, WIDTH, HEIGTH);
		levelEnergy[2] = image.getSubImage(2*WIDTH, 0, WIDTH, HEIGTH);
		levelEnergy[3] = image.getSubImage(0, HEIGTH, WIDTH, HEIGTH);
		levelEnergy[4] = image.getSubImage(WIDTH, HEIGTH, WIDTH, HEIGTH);
		levelEnergy[5] = image.getSubImage(2*WIDTH, HEIGTH, WIDTH, HEIGTH);
		image = levelEnergy[0]; // full
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		str = getValue()+"/"+getMax();
		CachedResourceLoader.fontSmall.drawString(position.x, position.y+47, str);
		g.drawImage(image, position.x + CachedResourceLoader.fontSmall.getWidth(str)/2 - image.getWidth()/2, position.y);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		int val = getValue()*100/getMax();
		if(val==100) {
			image = levelEnergy[0]; 
		} else if(val>=75){
			image = levelEnergy[1]; 
		} else if(val>=50){
			image = levelEnergy[2]; 
		} else if(val>=25){
			image = levelEnergy[3]; 
		} else if(val>5){
			image = levelEnergy[4]; 
		} else {
			image = levelEnergy[5]; 
		}
	}

}
